﻿using System;

///These classes were contributed by Carl Nelson
///They provide conversion operators to make working with TextType and StringType more friendly.

namespace DOJ.LEISP.LEXS
{
    public partial class @string
    {
        public static implicit operator @string(string normalDotNETString)
        {
            @string DES2String = new @string();
            DES2String.Value = normalDotNETString;
            return DES2String;
        }

        public static implicit operator string(@string des2String)
        {
            if (null != des2String)
            {
                return des2String.Value;
            }
            else
            {
                return String.Empty;
            }
        }
    }

    public partial class TextType
    {
        public static implicit operator string(TextType des2TextType)
        {
            if (null != des2TextType)
            {
                return des2TextType.Value;
            }
            else
            {
                return String.Empty;
            }
        }

        public static implicit operator TextType(string normalDotNETString)
        {
            TextType DES2TextType = new TextType();
            DES2TextType.Value = normalDotNETString;
            return DES2TextType;
        }
    }

    public partial class boolean
    {
        public static implicit operator bool(boolean des2Boolean)
        {
            if (null != des2Boolean)
            {
                return des2Boolean.Value;
            }
            else
            {
                return false;
            }
        }

        public static implicit operator boolean(bool normalDotNetBool)
        {
            boolean des2bool = new boolean();
            des2bool.Value = normalDotNetBool;
            return des2bool;
        }
    }

    public partial class nonNegativeInteger
    {
        public static implicit operator string(nonNegativeInteger des2IntString)
        {
            if (null != des2IntString)
            {
                return des2IntString.Value;
            }
            else
            {
                return null;
            }
        }

        public static implicit operator nonNegativeInteger(string normalDotNetIntString)
        {
            nonNegativeInteger des2IntString = new nonNegativeInteger();
            des2IntString.Value = normalDotNetIntString;
            return des2IntString;
        }

        public static implicit operator int(nonNegativeInteger des2IntString)
        {
            if (null != des2IntString)
            {
                return Convert.ToInt32(des2IntString.Value);
            }
            else
            {
                return 0;
            }
        }

        public static implicit operator nonNegativeInteger(int normalDotNetIntString)
        {
            nonNegativeInteger des2IntString = new nonNegativeInteger();
            des2IntString.Value = normalDotNetIntString.ToString();
            return des2IntString;
        }
    }


    public partial class PersonNameTextType
    {
        public static implicit operator string(PersonNameTextType des2TextType)
        {
            if (null != des2TextType)
            {
                return des2TextType.Value;
            }
            else
            {
                return String.Empty;
            }

        }
        public static implicit operator PersonNameTextType(string normalDotNETString)
        {
            PersonNameTextType DES2TextType = new PersonNameTextType();
            DES2TextType.Value = normalDotNETString;
            return DES2TextType;
        }
    }

    public partial class dateTime
    {
        public static implicit operator DateTime(dateTime des2DateTime)
        {
            if (null != des2DateTime)
            {
                return des2DateTime.Value;
            }
            else
            {
                //TODO: Would rather return null here...
                return DateTime.MinValue;
            }

        }

        public static implicit operator dateTime(DateTime normalDotNetDateTime)
        {
            dateTime DES2DateTime = new dateTime();
            DES2DateTime.Value = normalDotNetDateTime;
            return DES2DateTime;
        }
    }
}
